<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - code analysis - include/caffe/util/io.hpp</title>
  <link rel="stylesheet" type="text/css" href="../../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../../index.html">top level</a> - <a href="index.html">include/caffe/util</a> - io.hpp<span style="font-size: 80%;"> (source / <a href="io.hpp.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">code analysis</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">2</td>
            <td class="headerCovTableEntry">7</td>
            <td class="headerCovTableEntryLo">28.6 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2020-09-11 22:25:26</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">0</td>
            <td class="headerCovTableEntry">1</td>
            <td class="headerCovTableEntryLo">0.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : #ifndef CAFFE_UTIL_IO_H_</a>
<span class="lineNum">       2 </span>            : #define CAFFE_UTIL_IO_H_
<span class="lineNum">       3 </span>            : 
<span class="lineNum">       4 </span>            : #include &lt;boost/filesystem.hpp&gt;
<span class="lineNum">       5 </span>            : #include &lt;iomanip&gt;
<span class="lineNum">       6 </span>            : #include &lt;iostream&gt;  // NOLINT(readability/streams)
<span class="lineNum">       7 </span>            : #include &lt;string&gt;
<span class="lineNum">       8 </span>            : 
<span class="lineNum">       9 </span>            : #include &quot;google/protobuf/message.h&quot;
<span class="lineNum">      10 </span>            : 
<span class="lineNum">      11 </span>            : #include &quot;caffe/common.hpp&quot;
<span class="lineNum">      12 </span>            : #include &quot;caffe/proto/caffe.pb.h&quot;
<span class="lineNum">      13 </span>            : #include &quot;caffe/util/format.hpp&quot;
<span class="lineNum">      14 </span>            : 
<span class="lineNum">      15 </span>            : #ifndef CAFFE_TMP_DIR_RETRIES
<span class="lineNum">      16 </span>            : #define CAFFE_TMP_DIR_RETRIES 100
<span class="lineNum">      17 </span>            : #endif
<span class="lineNum">      18 </span>            : 
<span class="lineNum">      19 </span>            : namespace caffe {
<span class="lineNum">      20 </span>            : 
<span class="lineNum">      21 </span>            : using ::google::protobuf::Message;
<span class="lineNum">      22 </span>            : using ::boost::filesystem::path;
<span class="lineNum">      23 </span>            : 
<span class="lineNum">      24 </span>            : inline void MakeTempDir(string* temp_dirname) {
<span class="lineNum">      25 </span>            :   temp_dirname-&gt;clear();
<span class="lineNum">      26 </span>            :   const path&amp; model =
<span class="lineNum">      27 </span>            :     boost::filesystem::temp_directory_path()/&quot;caffe_test.%%%%-%%%%&quot;;
<span class="lineNum">      28 </span>            :   for ( int i = 0; i &lt; CAFFE_TMP_DIR_RETRIES; i++ ) {
<span class="lineNum">      29 </span>            :     const path&amp; dir = boost::filesystem::unique_path(model).string();
<span class="lineNum">      30 </span>            :     bool done = boost::filesystem::create_directory(dir);
<span class="lineNum">      31 </span>            :     if ( done ) {
<span class="lineNum">      32 </span>            :       *temp_dirname = dir.string();
<span class="lineNum">      33 </span>            :       return;
<span class="lineNum">      34 </span>            :     }
<span class="lineNum">      35 </span>            :   }
<span class="lineNum">      36 </span>            :   LOG(FATAL) &lt;&lt; &quot;Failed to create a temporary directory.&quot;;
<span class="lineNum">      37 </span>            : }
<span class="lineNum">      38 </span>            : 
<span class="lineNum">      39 </span>            : inline void MakeTempFilename(string* temp_filename) {
<span class="lineNum">      40 </span>            :   static path temp_files_subpath;
<span class="lineNum">      41 </span>            :   static uint64_t next_temp_file = 0;
<span class="lineNum">      42 </span>            :   temp_filename-&gt;clear();
<span class="lineNum">      43 </span>            :   if ( temp_files_subpath.empty() ) {
<span class="lineNum">      44 </span>            :     string path_string=&quot;&quot;;
<span class="lineNum">      45 </span>            :     MakeTempDir(&amp;path_string);
<span class="lineNum">      46 </span>            :     temp_files_subpath = path_string;
<span class="lineNum">      47 </span>            :   }
<span class="lineNum">      48 </span>            :   *temp_filename =
<span class="lineNum">      49 </span>            :     (temp_files_subpath/caffe::format_int(next_temp_file++, 9)).string();
<span class="lineNum">      50 </span>            : }
<span class="lineNum">      51 </span>            : 
<span class="lineNum">      52 </span>            : bool ReadProtoFromTextFile(const char* filename, Message* proto);
<span class="lineNum">      53 </span>            : 
<span class="lineNum">      54 </span>            : inline bool ReadProtoFromTextFile(const string&amp; filename, Message* proto) {
<span class="lineNum">      55 </span><span class="lineCov">          1 :   return ReadProtoFromTextFile(filename.c_str(), proto);</span>
<span class="lineNum">      56 </span>            : }
<span class="lineNum">      57 </span>            : 
<span class="lineNum">      58 </span>            : inline void ReadProtoFromTextFileOrDie(const char* filename, Message* proto) {
<span class="lineNum">      59 </span>            :   CHECK(ReadProtoFromTextFile(filename, proto));
<span class="lineNum">      60 </span>            : }
<span class="lineNum">      61 </span>            : 
<span class="lineNum">      62 </span>            : inline void ReadProtoFromTextFileOrDie(const string&amp; filename, Message* proto) {
<span class="lineNum">      63 </span>            :   ReadProtoFromTextFileOrDie(filename.c_str(), proto);
<span class="lineNum">      64 </span>            : }
<span class="lineNum">      65 </span>            : 
<span class="lineNum">      66 </span>            : void WriteProtoToTextFile(const Message&amp; proto, const char* filename);
<span class="lineNum">      67 </span>            : inline void WriteProtoToTextFile(const Message&amp; proto, const string&amp; filename) {
<span class="lineNum">      68 </span>            :   WriteProtoToTextFile(proto, filename.c_str());
<span class="lineNum">      69 </span>            : }
<span class="lineNum">      70 </span>            : 
<span class="lineNum">      71 </span>            : bool ReadProtoFromBinaryFile(const char* filename, Message* proto);
<span class="lineNum">      72 </span>            : 
<span class="lineNum">      73 </span>            : inline bool ReadProtoFromBinaryFile(const string&amp; filename, Message* proto) {
<span class="lineNum">      74 </span><span class="lineCov">          1 :   return ReadProtoFromBinaryFile(filename.c_str(), proto);</span>
<a name="75"><span class="lineNum">      75 </span>            : }</a>
<span class="lineNum">      76 </span>            : 
<span class="lineNum">      77 </span><span class="lineNoCov">          0 : inline void ReadProtoFromBinaryFileOrDie(const char* filename, Message* proto) {</span>
<span class="lineNum">      78 </span><span class="lineNoCov">          0 :   CHECK(ReadProtoFromBinaryFile(filename, proto));</span>
<span class="lineNum">      79 </span><span class="lineNoCov">          0 : }</span>
<span class="lineNum">      80 </span>            : 
<span class="lineNum">      81 </span>            : inline void ReadProtoFromBinaryFileOrDie(const string&amp; filename,
<span class="lineNum">      82 </span>            :                                          Message* proto) {
<span class="lineNum">      83 </span>            :   ReadProtoFromBinaryFileOrDie(filename.c_str(), proto);
<span class="lineNum">      84 </span>            : }
<span class="lineNum">      85 </span>            : 
<span class="lineNum">      86 </span>            : 
<span class="lineNum">      87 </span>            : void WriteProtoToBinaryFile(const Message&amp; proto, const char* filename);
<span class="lineNum">      88 </span>            : inline void WriteProtoToBinaryFile(
<span class="lineNum">      89 </span>            :     const Message&amp; proto, const string&amp; filename) {
<span class="lineNum">      90 </span><span class="lineNoCov">          0 :   WriteProtoToBinaryFile(proto, filename.c_str());</span>
<span class="lineNum">      91 </span>            : }
<span class="lineNum">      92 </span>            : 
<span class="lineNum">      93 </span>            : bool ReadFileToDatum(const string&amp; filename, const int label, Datum* datum);
<span class="lineNum">      94 </span>            : 
<span class="lineNum">      95 </span>            : inline bool ReadFileToDatum(const string&amp; filename, Datum* datum) {
<span class="lineNum">      96 </span><span class="lineNoCov">          0 :   return ReadFileToDatum(filename, -1, datum);</span>
<span class="lineNum">      97 </span>            : }
<span class="lineNum">      98 </span>            : 
<span class="lineNum">      99 </span>            : bool ReadImageToDatum(const string&amp; filename, const int label,
<span class="lineNum">     100 </span>            :     const int height, const int width, const bool is_color,
<span class="lineNum">     101 </span>            :     const std::string &amp; encoding, Datum* datum);
<span class="lineNum">     102 </span>            : 
<span class="lineNum">     103 </span>            : inline bool ReadImageToDatum(const string&amp; filename, const int label,
<span class="lineNum">     104 </span>            :     const int height, const int width, const bool is_color, Datum* datum) {
<span class="lineNum">     105 </span>            :   return ReadImageToDatum(filename, label, height, width, is_color,
<span class="lineNum">     106 </span>            :                           &quot;&quot;, datum);
<span class="lineNum">     107 </span>            : }
<span class="lineNum">     108 </span>            : 
<span class="lineNum">     109 </span>            : inline bool ReadImageToDatum(const string&amp; filename, const int label,
<span class="lineNum">     110 </span>            :     const int height, const int width, Datum* datum) {
<span class="lineNum">     111 </span>            :   return ReadImageToDatum(filename, label, height, width, true, datum);
<span class="lineNum">     112 </span>            : }
<span class="lineNum">     113 </span>            : 
<span class="lineNum">     114 </span>            : inline bool ReadImageToDatum(const string&amp; filename, const int label,
<span class="lineNum">     115 </span>            :     const bool is_color, Datum* datum) {
<span class="lineNum">     116 </span>            :   return ReadImageToDatum(filename, label, 0, 0, is_color, datum);
<span class="lineNum">     117 </span>            : }
<span class="lineNum">     118 </span>            : 
<span class="lineNum">     119 </span>            : inline bool ReadImageToDatum(const string&amp; filename, const int label,
<span class="lineNum">     120 </span>            :     Datum* datum) {
<span class="lineNum">     121 </span>            :   return ReadImageToDatum(filename, label, 0, 0, true, datum);
<span class="lineNum">     122 </span>            : }
<span class="lineNum">     123 </span>            : 
<span class="lineNum">     124 </span>            : inline bool ReadImageToDatum(const string&amp; filename, const int label,
<span class="lineNum">     125 </span>            :     const std::string &amp; encoding, Datum* datum) {
<span class="lineNum">     126 </span>            :   return ReadImageToDatum(filename, label, 0, 0, true, encoding, datum);
<span class="lineNum">     127 </span>            : }
<span class="lineNum">     128 </span>            : 
<span class="lineNum">     129 </span>            : bool DecodeDatumNative(Datum* datum);
<span class="lineNum">     130 </span>            : bool DecodeDatum(Datum* datum, bool is_color);
<span class="lineNum">     131 </span>            : 
<span class="lineNum">     132 </span>            : #ifdef USE_OPENCV
<span class="lineNum">     133 </span>            : cv::Mat ReadImageToCVMat(const string&amp; filename,
<span class="lineNum">     134 </span>            :     const int height, const int width, const bool is_color);
<span class="lineNum">     135 </span>            : 
<span class="lineNum">     136 </span>            : cv::Mat ReadImageToCVMat(const string&amp; filename,
<span class="lineNum">     137 </span>            :     const int height, const int width);
<span class="lineNum">     138 </span>            : 
<span class="lineNum">     139 </span>            : cv::Mat ReadImageToCVMat(const string&amp; filename,
<span class="lineNum">     140 </span>            :     const bool is_color);
<span class="lineNum">     141 </span>            : 
<span class="lineNum">     142 </span>            : cv::Mat ReadImageToCVMat(const string&amp; filename);
<span class="lineNum">     143 </span>            : 
<span class="lineNum">     144 </span>            : cv::Mat DecodeDatumToCVMatNative(const Datum&amp; datum);
<span class="lineNum">     145 </span>            : cv::Mat DecodeDatumToCVMat(const Datum&amp; datum, bool is_color);
<span class="lineNum">     146 </span>            : 
<span class="lineNum">     147 </span>            : void CVMatToDatum(const cv::Mat&amp; cv_img, Datum* datum);
<span class="lineNum">     148 </span>            : #endif  // USE_OPENCV
<span class="lineNum">     149 </span>            : 
<span class="lineNum">     150 </span>            : }  // namespace caffe
<span class="lineNum">     151 </span>            : 
<span class="lineNum">     152 </span>            : #endif   // CAFFE_UTIL_IO_H_
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.12</a></td></tr>
  </table>
  <br>

</body>
</html>
